package com.mysoft.gfyx.common.rpc.opensearch.dto;

import com.mysoft.framework.common.exception.BusinessLogicException;
import lombok.Data;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Objects;

@Data
public class SearchWinBidRequestDto extends SearchBaseRequestDto {
    private String keyword;
    private String province_code;
    private String city_code;
    private String company_type_label;
    private String source_type;
    private String source_sub;
    private String source_sub_code;
    private String publish_date_lower;
    private String publish_date_upper;
    private String bid_price_lower;
    private String bid_price_upper;
    private String area;
    private String created_time;

    private String developer_top_100_label;
    private String new_area_expand_label;
    private String new_decorate_expand_label;
    private String new_land_usage_expand_label;
    private String price_gt_avg_label;

    private int page = 1;
    private int page_size;

    protected void setFilterByField(String field, String operatorType, Object value) {
        switch (field) {
            case "first_winbid_price":
                BigDecimal price = new BigDecimal(value.toString());
                price = price.multiply(new BigDecimal(10000));
                if ("ge".equals(operatorType) || "gt".equals(operatorType)) {
                    this.setBid_price_lower(price.toString());
                } else if ("le".equals(operatorType) || "lt".equals(operatorType)) {
                    this.setBid_price_upper(price.toString());
                }
                break;
            case "publish_time":
                if ("ge".equals(operatorType) || "gt".equals(operatorType)) {
                    this.setPublish_date_lower(value.toString());
                } else if ("le".equals(operatorType) || "lt".equals(operatorType)) {
                    this.setPublish_date_upper(value.toString());
                }
                break;
            case "tags_set":
                if (value instanceof ArrayList<?>) {
                    for (Object tag : (ArrayList<?>) value) {
                        this.setTags(tag.toString());
                    }
                }
                break;
            case "source_sub_code":
                if (Objects.equals(value.toString(), "website_bid")) {
                    this.setSource_sub("官网招标");
                } else if (Objects.equals(value.toString(), "trading_center")) {
                    this.setSource_sub("公共交易中心");
                }
                break;
            default:
                this.dynamicSetProperty(field, value);
        }
    }

    protected void setTags(String tags) {
        switch (tags) {
            case "developer_top_100_label":
                this.setDeveloper_top_100_label("地产百强");
                break;
            case "new_decorate_expand_label":
                this.setNew_decorate_expand_label("新精装客群");
                break;
            case "new_land_usage_expand_label":
                this.setNew_land_usage_expand_label("新住宅客群");
                break;
            case "new_area_expand_label":
                this.setNew_area_expand_label("新区域拓展");
                break;
            case "price_gt_avg_label":
                this.setPrice_gt_avg_label("高端项目客群");
                break;
            default:
                throw new BusinessLogicException("未定义的标签" + tags);
        }
    }
}
